package com.binsoft.ndtta;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class NdttaDatabaseHelper extends SQLiteOpenHelper {

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table if not exists " + Constants.DATABASE_TABLE + " (_id integer primary key autoincrement, "
			+ "date integer, division integer, home integer, away integer, homescore integer, awayscore integer);";

	public NdttaDatabaseHelper(Context context) 
	{
		super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
		
		Log.i( NdttaDatabaseHelper.class.getName() , "Creating database helper");
	}

	// Method is called during creation of the database
	@Override
	public void onCreate(SQLiteDatabase database) 
	{
		Log.i( NdttaDatabaseHelper.class.getName(), "Creating database table " + Constants.DATABASE_TABLE );
		
		database.execSQL(DATABASE_CREATE);
	}

	// Method is called during an upgrade of the database, e.g. if you increase
	// the database version
	@Override
	public void onUpgrade(SQLiteDatabase database, int oldVersion,
			int newVersion) 
	{
		Log.w(NdttaDatabaseHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		database.execSQL("DROP TABLE IF EXISTS " + Constants.DATABASE_TABLE);
		onCreate(database);
	}

	@Override
	public void onOpen(SQLiteDatabase database)
	{
		// TODO Auto-generated method stub
		super.onOpen(database);
		
		Log.i(NdttaDatabaseHelper.class.getName(), "Calling onOpen");
		
		database.execSQL(DATABASE_CREATE);
	}
}